(function($, doc, phone) {
	mui.init();
	mui.plusReady(function() {
		var settings = app.getSettings();
		var state = app.getState();
		var uid = state.user_id;

		var list = document.getElementById('list');
		var header = document.querySelector('header');
		//calc hieght
		list.style.height = (plus.display.resolutionHeight - 70) + 'px';
		//create
		window.indexedList = new mui.IndexedList(list);
		//var cdata = null;
		//console.log(cdata);
		var phones = sysphone.getFriendPin();
		function renderlist(){
			for(var p in phones){
				for(var j in phones[p]) {
					
					phones[p][j]['avatar'] = app.avatar(phones[p][j]['f_id'], '../../static/images/addfriend_py.png');
					if(phones[p][j]['f_id'] == uid) {
						delete phones[p][j];
					}
				}
			}
			document.querySelector("#list-area").innerHTML = template('list-template', {
				"flist": phones
			});
		}
		if(phones.length > 0) {
			renderlist();
		}else{
			setTimeout(function() {
				var phones = sysphone.getFriendPin();
				renderlist();
			}, 1000);
		}
		//initheight();
		mui("#list-area").on("tap", "a", function() {
			var fid = this.getAttribute("fid");
			var head = this.getAttribute("head");
			var fname = this.getAttribute("title");
			var phone = this.getAttribute("phone");
			var targets = '/pages/user/other_detail.html';
			mui.openWindow({
				url: targets,
				id: targets,
				extras: {
					fid: fid,
					head: head,
					fname: fname,
					phone : phone,
					back_id:'friendlist'
				}
			});

		});


        window.addEventListener('refreshList', function(event) {
        	phones = sysphone.getFriendPin();
			if(phones.length > 0) {
			     renderlist();
			}else{
				setTimeout(function() {
					var phones = sysphone.getFriendPin();
					renderlist();
				}, 1000);
			}
		});
		
	});
}(mui, document, window.phone));